import { Office, StatusValue, UserType } from '@/enum/common.enum';
import { ApiProperty } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import { $enum } from 'ts-enum-util';
import {
  Column,
  CreateDateColumn,
  Entity,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity('user')
export class UserEntity {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  @ApiProperty({ type: String, description: '主键' })
  public id: number;
  @ApiProperty({ type: String, description: '用户名' })
  @Column({ type: 'varchar', length: 200, nullable: false, comment: '用户名' })
  public username: string;
  @ApiProperty({ type: String, description: '密码' })
  @Exclude({ toPlainOnly: true })
  @Column({ type: 'varchar', length: 200, nullable: false, comment: '密码' })
  public password: string;
  @ApiProperty({
    type: String,
    description: '员工状态 0:禁用 1:启用',
    enum: $enum(StatusValue).getValues,
  })
  @Column({ type: 'tinyint', default: StatusValue.ACTIVE, comment: '状态 1-有效 0-无效' })
  public status: StatusValue;

  @ApiProperty({
    type: String,
    description: '员工类型 1:超级管理员 2:普通用户',
    enum: $enum(UserType).getValues,
  })
  @Column({ type: 'tinyint', default: UserType.USER, comment: '用户类型 1-超级管理员 2-普通用户' })
  public type: UserType;

  @ApiProperty({ description: '邮箱', required: false })
  @Column({ type: 'varchar', comment: '邮箱', default: '', length: 200 })
  public email?: string;

  @ApiProperty({ description: '简介' })
  @Column({ type: 'varchar', comment: '简介', default: '' })
  public summary?: string;

  @ApiProperty({ description: '身份证' })
  @Column({ type: 'varchar', comment: '身份证', default: '' })
  public idCard?: string;

  @ApiProperty({ description: '照片', required: false })
  @Column({ type: 'varchar', comment: '照片', default: '' })
  public photo?: string;

  @ApiProperty({ type: String, description: '头像url' })
  @Column({ type: 'longtext', comment: '头像地址' })
  public avatar: string;

  @Column({ type: 'varchar', length: 20, name: 'phone_num', comment: '电话号', default: '' })
  @ApiProperty({ type: String, description: '电话号', default: '' })
  public phoneNum: string;

  @Column({ type: 'tinyint', default: Office.TEACHER, name: 'office', comment: '职位' })
  @ApiProperty({ description: '职位', type: String, enum: $enum(Office).getValues() })
  public office?: Office;

  @ApiProperty({ type: String, description: '创建日期' })
  @CreateDateColumn({
    type: 'timestamp',
    name: 'create_time',
    comment: '创建时间',
  })
  public createDate: Date;
  @ApiProperty({ type: String, description: '更新日期' })
  @UpdateDateColumn({
    type: 'timestamp',
    name: 'update_time',
    comment: '更新时间',
  })
  public updateDate: Date;
}
